package com.qianyu.project.web.controller.mfy;

import com.qianyu.project.core.context.user.FlowUserProvider;
import com.qianyu.project.entity.DeviceRepair;
import com.qianyu.project.entity.DeviceScrap;
import com.qianyu.project.service.IAttachemenInfoService;
import com.qianyu.project.service.IDeviceRepairService;
import com.qianyu.project.service.IDeviceScrapService;
import com.qianyu.project.utils.Result;
import com.qianyu.project.utils.ResultTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Map;

/**
 * @Author mfy
 * @desc
 */
@RestController
@RequestMapping("/deviceScraps")
public class DeviceScrapConrtroller {

    @Autowired
    private IDeviceScrapService deviceScrapService;

    @Autowired
    private FlowUserProvider flowUserProvider;
    @Autowired
    private IAttachemenInfoService attachemenInfoService;

    @PostMapping("")
    public Result save(@RequestBody Map<String,Object> params){
        DeviceScrap dc = new DeviceScrap();
        Map<String,Object> mapDrp = (Map<String, Object>) params.get("DeviceScrap");
        dc.setFillUser(flowUserProvider.getFlowUser().getId().intValue());
        dc.setUpdateDate(LocalDate.now().toString());
        dc.setApproveStatus(1+"");
        dc.setMaterialId(Integer.valueOf(mapDrp.get("materialId")+""));
        dc.setEid(Integer.valueOf(mapDrp.get("eid")+""));
        dc.setDid(Integer.valueOf(mapDrp.get("did")+""));
        dc.setBaofeidate(mapDrp.get("baofeidate")+"");
        dc.setYuanyin(mapDrp.get("yuanyin")+"");
        dc.setMoney(BigDecimal.valueOf(Double.valueOf(mapDrp.get("money")+"")));
        dc.setShenqingdate(mapDrp.get("shenqingdate")+"");
        dc.setComment(mapDrp.get("comment")+"");
        dc.setShuoming(mapDrp.get("shuoming")+"");
        deviceScrapService.Mysave(dc,params);
        return ResultTool.success();
    }


    @PutMapping("")
    public Result update(@RequestBody Map<String,Object> params){
        DeviceScrap dc = new DeviceScrap();
        Map<String,Object> mapDrp = (Map<String, Object>) params.get("DeviceScrap");
        dc.setId(Integer.valueOf(mapDrp.get("id")+""));
        dc.setFillUser(flowUserProvider.getFlowUser().getId().intValue());
        dc.setUpdateDate(LocalDate.now().toString());
        dc.setApproveStatus(1+"");
        dc.setMaterialId(Integer.valueOf(mapDrp.get("materialId")+""));
        dc.setEid(Integer.valueOf(mapDrp.get("eid")+""));
        dc.setDid(Integer.valueOf(mapDrp.get("did")+""));
        dc.setBaofeidate(mapDrp.get("baofeidate")+"");
        dc.setYuanyin(mapDrp.get("yuanyin")+"");
        dc.setMoney(BigDecimal.valueOf(Double.valueOf(mapDrp.get("money")+"")));
        dc.setShenqingdate(mapDrp.get("shenqingdate")+"");
        dc.setComment(mapDrp.get("comment")+"");
        dc.setShuoming(mapDrp.get("shuoming")+"");
        deviceScrapService.saveOrUpdate(dc);
        deviceScrapService.Myupdate(dc,params);
        return ResultTool.success();
    }
    @GetMapping("")
    public Result list(@RequestParam Map<String,String> params){
        return ResultTool.success(deviceScrapService.Mylist(params));
    }
    @GetMapping("/listNopage")
    public Result listNopage(@RequestParam Map<String,String> params){
        return ResultTool.success(deviceScrapService.listNopage(params));
    }

    @GetMapping("/selectEnclosures/{attachIds}")
    public Result selectEnclosures(@PathVariable String attachIds){
        return ResultTool.success(attachemenInfoService.selectEnclosures7(attachIds));
    }
}
